/*
 * @Author: sxb
 * @Email: sxb@mail.com
 * @Date: 2020-02-25 16:52:08
 * @Descripttion: 
 */
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';

import { Observable } from "rxjs"

@Injectable({
  providedIn: 'root'
})
export class PurchaseManageService {

  // 出入库：采购单表管理
  // 查询采购单表
  private CGListUrl = '/api/po'
  async getRKList(data): Promise<Node> {
    let dataJson = {
      warehouseId:data.warehouseId,
      inCode:data.inCode,
      startDate:data.startDate,
      endDate:data.endDate,
      materialCode:data.materialCode,
      materialName:data.materialName,
      pocode:data.po,
      providerName:data.providerName,
      checkStatus:data.checkStatus,
      page:data.page,
      size:data.size
    }
    return new Promise<Node>((resolve, reject) => {
      this.http.get(this.CGListUrl, { params:dataJson }).subscribe((res: any) => {
        resolve(res);
      }, err => {
        reject(err)
      })
    })
  }

  // 出入库：接受入库明细管理
  private receiveInfoUrl = "/api/receiveInfo"
  getReceiveInfoList(data): Observable<any> {
    return this.http.get(this.receiveInfoUrl+"?foid="+ data.foid +"&page="+ data.page +"&size="+data.size+"&sort=updateDate,desc", {}).pipe()
  }
  postReceiveInfo(data): Observable<any> {
    return this.http.post(this.receiveInfoUrl, data).pipe()
  }
  putReceiveInfo(data): Observable<any> {
    return this.http.put(this.receiveInfoUrl, data).pipe()
  }
  delReceiveInfoByIds(data): Observable<any> {
    let _dataJson = {
        headers: new HttpHeaders({
            'Content-Type': 'application/json',
        }),
        body: data
    }
    return this.http.delete(this.receiveInfoUrl, _dataJson).pipe();
  }

  getCheckFirst(data) : Observable<any>{
    return this.http.get("/api/receiveInfo/checkfirst?materialId="+ data, {}).pipe();
  }
  postCheckStorage(data): Observable<any>{
    return this.http.post("/api/receiveInfo/checkstorage?id="+ data.id +"&isexpedited="+data.isexpedited, {}).pipe()
  }
  postConfirmStorage(data): Observable<any> {
    return this.http.post("/api/receiveInfo/confirmstorage", data).pipe()
  }
  postDirectStorage(data): Observable<any>{
    return this.http.post("/api/receiveInfo/directstorage?id="+ data.id, {}).pipe()
  }
  postRefuseStorage(data): Observable<any>{
    return this.http.post("/api/receiveInfo/refusestorage?id="+ data.id+"&suggestion="+ data.suggestion, {}).pipe()
  }
  /**
   * @Author: sxb
   * @Email: sxb@mail.com
   * @Date: 2020-03-31 14:49:25
   * @UseComponent: 
   * @Descripttion: 通过接受入库明细ID获取信息
   * @Return: 
   */
  postFindById(data): Observable<any>{
    return this.http.post("/api/receiveInfo/findById?id="+ data.id, {}).pipe()
  }

  constructor(
    private http:HttpClient
  ) { }
}
